// 推荐
function getRecommentShopList(callback, page) {
  if (page) {
    wx.request({
      data: {
        page
      },
      url: 'http://localhost:3000/api/allShop',
      success(res) {
        callback(res)
      }
    })
  } else {
    wx.request({
      url: 'http://localhost:3000/api/allShop',
      success(res) {
        callback(res)
      }
    })
  }
}


function getGouwu(cartItem, callback) {
  const userid = wx.getStorageSync('userid'); // 获取用户的 userid

  // 确保 userid 存在
  if (!userid) {
    callback({
      success: false,
      message: 'User ID is missing'
    });
    return;
  }

  wx.request({
    url: 'http://localhost:3000/api/addGouwu',
    method: 'POST',
    data: {
      _id: cartItem._id,
      cartItem, // 将购物车项封装在一个数组中
      userid: userid // 传递 userid
    },
    success(res) {
      callback(res); // 调用回调函数，处理返回结果
    },
    fail(err) {
      callback({
        success: false,
        message: err.message
      });
    }
  });
}


function getAllGouwu(callback, page) {
  if (page) {
    wx.request({
      data: {
        page
      },
      url: 'http://localhost:3000/api/getAllGouwu',
      success(res) {
        callback(res)
      }
    })
  } else {
    wx.request({
      url: 'http://localhost:3000/api/getAllGouwu',
      success(res) {
        callback(res)
      }
    })
  }
}


function delGouwu(id) {
  wx.request({
    method: 'POST',
    data: {
      id
    },
    url: 'http://localhost:3000/api/delGouwu',
  })
}




module.exports = {
  getRecommentShopList,
  getGouwu,
  getAllGouwu,
  delGouwu
}